<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="配置编码" :labelCol="labelColOne" :wrapperCol="wrapperColOne" >
              <a-input  v-model="model.code" placeholder="请输入"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="配置值" :labelCol="labelColOne" :wrapperCol="wrapperColOne" >
              <a-input  v-model="model.value" placeholder="请输入"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="描述" :labelCol="labelColOne" :wrapperCol="wrapperColOne" >
              <a-input  v-model="model.description" placeholder="请输入"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

      </a-form-model>
    </j-form-container>
  </a-spin>
</template>


<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import ATextarea from 'ant-design-vue/es/input/TextArea'
  import JUpload from '@/components/jeecg/JUpload'
  import { FormMixin } from '@/mixins/FormMixin'
  import { getDataOptionList } from '../../../utils/util'
  import { requestSetData, requestSetOptions } from '../../../utils/commonUtils'
  import moment from 'moment'

  export default {
    name: 'DataConfigForm',
    mixins: [ FormMixin],
    components: {
      ATextarea
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/admin/dataConfig/save",
          edit: "/admin/dataConfig/update",
          queryById: "/admin/dataConfig/detail"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      let $this = this;
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));


    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      handleChange(value) {
        console.log(`selected ${value}`);
      },
      onChange(e) {
        console.log('radio1 checked', e.target.value);
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            if(!this.model.id){
              httpurl+=this.url.add;
            }else{
              httpurl+=this.url.edit;
            }
            httpAction(httpurl,this.model,"post").then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>